package Admin;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

import javax.swing.JOptionPane;

import GroupClass.ConnectRMI;
import Project_etow.EtowInterface;

public class UpdateBill extends javax.swing.JDialog {

    private Payment pm;
    ConnectRMI      connectRMI = new ConnectRMI();
    private String  idbuill;
    private String  idbuillpayment;

    public String getIdbuill() {
        return idbuill;
    }

    public void setIdbuill(String idbuill) {
        this.idbuill = idbuill;
    }

    public String getIdbuillpayment() {
        return idbuillpayment;
    }

    public void setIdbuillpayment(String idbuillpayment) {
        this.idbuillpayment = idbuillpayment;
    }

    public UpdateBill(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    @SuppressWarnings("unchecked")
    private void initComponents() {

        lbname = new javax.swing.JLabel();
        txtname = new javax.swing.JTextField();
        lbcompanyname = new javax.swing.JLabel();
        txtcompanyname = new javax.swing.JTextField();
        lbpower = new javax.swing.JLabel();
        txtpower = new javax.swing.JTextField();
        lbwater = new javax.swing.JLabel();
        txtwater = new javax.swing.JTextField();
        btsubmit = new javax.swing.JButton();
        btcancel = new javax.swing.JButton();
        lbdatepayment = new javax.swing.JLabel();
        lbsecurity = new javax.swing.JLabel();
        txtsecurity = new javax.swing.JTextField();
        lbwashingrooms = new javax.swing.JLabel();
        txtwashingrooms = new javax.swing.JTextField();
        lbceanbuildingglasses = new javax.swing.JLabel();
        txtCleanBuildingGlasses = new javax.swing.JTextField();
        lbmaintenanceelevator = new javax.swing.JLabel();
        txtmaintenanceelevator = new javax.swing.JTextField();
        lbamountofparking = new javax.swing.JLabel();
        txtamountofparking = new javax.swing.JTextField();
        lbunitprice = new javax.swing.JLabel();
        txtunitprice = new javax.swing.JTextField();
        txtdateofpayment = new javax.swing.JTextField();
        lbemail = new javax.swing.JLabel();
        txtemail = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setBackground(java.awt.Color.red);

        lbname.setText("Name");

        lbcompanyname.setText("CompanyName");

        lbpower.setText("Power");

        lbwater.setText("Water");

        btsubmit.setText("Submit");
        btsubmit.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent arg0) {
                EtowInterface obj = null;
                Registry registry;
                try {
                    registry = LocateRegistry.getRegistry(connectRMI.host, connectRMI.port);
                    obj = (EtowInterface) registry.lookup(connectRMI.regis);
                    String idbuill = getIdbuill();
                    String idbuillpayment = getIdbuillpayment();
                    String unitprice = txtunitprice.getText();
                    String power = txtpower.getText();
                    String water = txtwater.getText();
                    String date = txtdateofpayment.getText();
                    String security = txtsecurity.getText();
                    String washingroom = txtwashingrooms.getText();
                    String clean = txtCleanBuildingGlasses.getText();
                    String mainte = txtmaintenanceelevator.getText();
                    String amount = txtamountofparking.getText();
                    
                    obj.updatebill(idbuill, idbuillpayment, unitprice, power,
                            water, date, security,
                            washingroom, clean, mainte,
                            amount);
                    JOptionPane.showMessageDialog(null, "Update successfully");
                    
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(null, "Update Fail");
                    e.getMessage();
                }
               
            }
        });

        btcancel.setText("Cancel");

        lbdatepayment.setText("Date Of Payment");

        lbsecurity.setText("Security");

        lbwashingrooms.setText("WashingRooms");

        lbceanbuildingglasses.setText("CleanBuildingGlasses");

        lbmaintenanceelevator.setText("MaintenanceElevator");

        lbamountofparking.setText("AmountOfParking");

        lbunitprice.setText("UnitPrice");

        lbemail.setText("Email");

        txtname.setText(pm.getA0());
        txtcompanyname.setText(pm.getA1());
        txtemail.setText(pm.getA2());
        txtunitprice.setText(pm.getA4());
        txtpower.setText(pm.getA5());
        txtwater.setText(pm.getA6());
        txtsecurity.setText(pm.getA7());
        txtwashingrooms.setText(pm.getA8());
        txtCleanBuildingGlasses.setText(pm.getA9());
        txtmaintenanceelevator.setText(pm.getA10());
        txtamountofparking.setText(pm.getA11());
        txtdateofpayment.setText(pm.getA12());

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(
                        layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(
                                        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(lbdatepayment)
                                                .addComponent(lbamountofparking)
                                                .addComponent(lbmaintenanceelevator)
                                                .addComponent(lbceanbuildingglasses)
                                                .addComponent(lbwashingrooms)
                                                .addComponent(lbsecurity)
                                                .addComponent(lbwater)
                                                .addComponent(lbpower)
                                                .addComponent(lbname)
                                                .addComponent(lbemail)
                                                .addGroup(
                                                        layout.createSequentialGroup()
                                                                .addGroup(
                                                                        layout.createParallelGroup(
                                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                                                .addComponent(lbunitprice)
                                                                                .addComponent(lbcompanyname))
                                                                .addGap(58, 58, 58)
                                                                .addGroup(
                                                                        layout.createParallelGroup(
                                                                                javax.swing.GroupLayout.Alignment.TRAILING,
                                                                                false)
                                                                                .addComponent(txtcompanyname)
                                                                                .addComponent(
                                                                                        txtunitprice,
                                                                                        javax.swing.GroupLayout.Alignment.LEADING)
                                                                                .addComponent(
                                                                                        txtemail,
                                                                                        javax.swing.GroupLayout.Alignment.LEADING)
                                                                                .addComponent(
                                                                                        txtname,
                                                                                        javax.swing.GroupLayout.Alignment.LEADING,
                                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                        194, Short.MAX_VALUE)
                                                                                .addComponent(
                                                                                        txtpower,
                                                                                        javax.swing.GroupLayout.Alignment.LEADING,
                                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                        200, Short.MAX_VALUE)
                                                                                .addComponent(
                                                                                        txtwater,
                                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                        200, Short.MAX_VALUE)
                                                                                .addComponent(
                                                                                        txtsecurity,
                                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                        200, Short.MAX_VALUE)
                                                                                .addComponent(
                                                                                        txtwashingrooms,
                                                                                        javax.swing.GroupLayout.Alignment.LEADING,
                                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                        200, Short.MAX_VALUE)
                                                                                .addComponent(
                                                                                        txtCleanBuildingGlasses,
                                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                        200, Short.MAX_VALUE)
                                                                                .addComponent(
                                                                                        txtmaintenanceelevator,
                                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                        200, Short.MAX_VALUE)
                                                                                .addComponent(
                                                                                        txtamountofparking,
                                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                        200, Short.MAX_VALUE)
                                                                                .addComponent(
                                                                                        txtdateofpayment,
                                                                                        javax.swing.GroupLayout.Alignment.LEADING,
                                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                        200, Short.MAX_VALUE)
                                                                                .addGroup(
                                                                                        javax.swing.GroupLayout.Alignment.LEADING,
                                                                                        layout.createSequentialGroup()
                                                                                                .addComponent(btsubmit)
                                                                                                .addPreferredGap(
                                                                                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                                                .addComponent(btcancel)))))
                                .addContainerGap(18, Short.MAX_VALUE)));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(
                                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(lbname)
                                        .addComponent(txtname, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(
                                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(lbcompanyname)
                                        .addComponent(txtcompanyname, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(
                                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(lbemail)
                                        .addComponent(txtemail, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(
                                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(txtunitprice, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(lbunitprice))
                        .addGap(18, 18, 18)
                        .addGroup(
                                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(lbpower)
                                        .addComponent(txtpower, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(
                                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(lbwater)
                                        .addComponent(txtwater, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(
                                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(lbsecurity)
                                        .addComponent(txtsecurity, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(
                                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(lbwashingrooms)
                                        .addComponent(txtwashingrooms, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(
                                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(lbceanbuildingglasses)
                                        .addComponent(txtCleanBuildingGlasses, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(
                                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(lbmaintenanceelevator)
                                        .addComponent(txtmaintenanceelevator, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(
                                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(lbamountofparking)
                                        .addComponent(txtamountofparking, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(
                                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(lbdatepayment)
                                        .addComponent(txtdateofpayment, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(
                                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(btsubmit).addComponent(btcancel))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        pack();
    }

    public static void main(String args[]) {

        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(UpdateBill.class.getName())
                    .log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(UpdateBill.class.getName())
                    .log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(UpdateBill.class.getName())
                    .log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(UpdateBill.class.getName())
                    .log(java.util.logging.Level.SEVERE, null, ex);
        }

        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                UpdateBill dialog = new UpdateBill(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    private javax.swing.JButton    btcancel;
    private javax.swing.JButton    btsubmit;
    private javax.swing.JLabel     lbamountofparking;
    private javax.swing.JLabel     lbceanbuildingglasses;
    private javax.swing.JLabel     lbcompanyname;
    private javax.swing.JLabel     lbdatepayment;
    private javax.swing.JLabel     lbemail;
    private javax.swing.JLabel     lbmaintenanceelevator;
    private javax.swing.JLabel     lbname;
    private javax.swing.JLabel     lbpower;
    private javax.swing.JLabel     lbsecurity;
    private javax.swing.JLabel     lbunitprice;
    private javax.swing.JLabel     lbwashingrooms;
    private javax.swing.JLabel     lbwater;
    private javax.swing.JTextField txtCleanBuildingGlasses;
    private javax.swing.JTextField txtamountofparking;
    private javax.swing.JTextField txtcompanyname;
    private javax.swing.JTextField txtdateofpayment;
    private javax.swing.JTextField txtemail;
    private javax.swing.JTextField txtmaintenanceelevator;
    private javax.swing.JTextField txtname;
    private javax.swing.JTextField txtpower;
    private javax.swing.JTextField txtsecurity;
    private javax.swing.JTextField txtunitprice;
    private javax.swing.JTextField txtwashingrooms;
    private javax.swing.JTextField txtwater;

}
